/*!
 * \file __frssl_config_add.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frxml_parse.h"
#include "frlog.h"
#include "conntrack.h"
#include "frssl_config.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


extern int __frssl_config_del(u_int ui_ip, u_short us_port, const char *p_domain);

extern int __frssl_config_add(u_int ui_ip, u_short us_port
        , const char *p_file_ssl, const char *p_passwd, const char *p_domain);

static void __case1(void)
{
    FRSSL_info *p_ssl_info = NULL;
    int i_ret = 0;

    frssl_config_init();

    p_ssl_info = (FRSSL_info *)frmalloc (sizeof (FRSSL_info));
    memset (p_ssl_info, 0x00, sizeof (FRSSL_info));

    p_ssl_info->i_action = 1;
    p_ssl_info->p_file = frstrdup ("ssl_file");
    p_ssl_info->ui_ip = 19216811;
    p_ssl_info->us_port = 80;
    p_ssl_info->p_passwd = frstrdup ("ssl_passwd");
    p_ssl_info->p_domain = frstrdup ("p_domain");

    i_ret = __frssl_config_add(p_ssl_info->ui_ip, p_ssl_info->us_port, p_ssl_info->p_file, p_ssl_info->p_passwd, p_ssl_info->p_domain);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    i_ret = __frssl_config_del(p_ssl_info->ui_ip, p_ssl_info->us_port, p_ssl_info->p_domain);


    frfree (p_ssl_info->p_passwd);
    frfree (p_ssl_info->p_file);
    frfree (p_ssl_info->p_domain);
    frfree (p_ssl_info);

    frssl_config_destroy();

    return;

}


static void __case2(void)
{
    FRSSL_info *p_ssl_info = NULL;
    int i_ret = 0;

    frssl_config_init();

    p_ssl_info = (FRSSL_info *)frmalloc (sizeof (FRSSL_info));
    memset (p_ssl_info, 0x00, sizeof (FRSSL_info));

    p_ssl_info->i_action = 1;
    p_ssl_info->p_file = NULL;
    p_ssl_info->ui_ip = 19216811;
    p_ssl_info->us_port = 80;
    p_ssl_info->p_passwd = frstrdup ("ssl_passwd");
    p_ssl_info->p_domain = frstrdup ("p_domain");

    i_ret = __frssl_config_add(p_ssl_info->ui_ip, p_ssl_info->us_port, p_ssl_info->p_file, p_ssl_info->p_passwd, p_ssl_info->p_domain);


    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree (p_ssl_info->p_passwd);
    frfree (p_ssl_info->p_file);
    frfree (p_ssl_info->p_domain);
    frfree (p_ssl_info);
    frssl_config_destroy();

    return;

}


int add_suite___frssl_config_add(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frssl_config __frssl_config_add()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);

    return FR_SUCC;
}
